package persistence;

import java.util.List;

import model.Customer;

import org.hibernate.Query;
import org.hibernate.Session;





public class Login{
	


/**
 * 
 * @param Customer
 * @return true if Customer is existed
 */
    public static boolean canLogin(Customer customer){
	    Session session=HibernateUtil.openSession();
	    
        String hql = "from Customer c where c.name=:name and c.password=:password";     
        Query query = session.createQuery(hql);     
        query.setParameter("name", customer.getName());     
        query.setParameter("password", customer.getPassword());
        
        @SuppressWarnings("unchecked")
		List<Customer> list = query.list();     
	    
	    session.close();

	    return list.isEmpty()?false:true;
	}
    
    /**
     * 
     * @param name
     * @param password
     * @return true if name and password is existed
     */
    
    public static boolean canLogin(String name, String password){
 	    Session session=HibernateUtil.openSession();

         String hql = "from Customer c where c.name=:name and c.password=:password";     
         Query query = session.createQuery(hql);     
         query.setParameter("name", name);     
         query.setParameter("password", password);
         
         @SuppressWarnings("unchecked")
 		List<Customer> list = query.list();     
 	    
 	    session.close();

 	    return list.isEmpty()?false:true;
 	}
    

    
}

